package com.tianji.learning.listener;

import com.tianji.api.dto.remark.LikedTimesDTO;
import com.tianji.common.constants.MqConstants;
import com.tianji.learning.service.IInteractionReplyService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 监听点赞消息
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class LikedRecordListener {

    private final IInteractionReplyService interactionReplyService;

    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = "qa.liked.times.queue", durable = "true"),
            exchange = @Exchange(value = MqConstants.Exchange.LIKE_RECORD_EXCHANGE),
            key = MqConstants.Key.QA_LIKED_TIMES_KEY))
    public void listenQaLikedTimes(List<LikedTimesDTO> dto) {
        log.info("收到点赞消息,消息内容:{}", dto);
        interactionReplyService.updateLikeRecord(dto);
    }
}
